package impl;

import anaydis.sort.SorterType;
import java.util.Comparator;
import java.util.List;


public class InsertionSorter extends AbstractSorter{
    public <T> void sort(Comparator<T> tComparator, List<T> ts) {
        int N = ts.size();
        for (int i = 0; i < N; i++)
        {
            for (int j = i; j > 0; j--)
            {
                if (greater(tComparator, ts, j-1, j))
                {
                    swap(ts, j, j-1);
                }else {
                    break;
                }
            }
        }        
    }

    public <T> void sort(Comparator<T> tComparator, List<T> list, int left, int right) {
        for (int i = left; i < right; i++) {
            for (int j = i; j > left; j--) {
                if (!greater(tComparator,list, j, j - 1)) {
                    swap(list, j, j - 1);
                } else {
                    break;
                }
            }
        }
    }

    public InsertionSorter() {
        super(SorterType.INSERTION);
    }
}
